package com.juc.concurrency.jucExample.threadLocal;

/**
 * ThreadLocal存储线程id
 * 1.filter执行add方法
 * 2.controller执行getId获取requestHolder中的值进行验证
 * 3.拦截器interceptor执行remove方法
 */
public class RequestHolder {

    private final static ThreadLocal<Long> requestHolder = new ThreadLocal<>();

    public static void add(Long id) {
        requestHolder.set(id);
    }

    public static Long getId() {
        return requestHolder.get();
    }

    public static void remove() {
        requestHolder.remove();
    }
}
